<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
  <meta name="description" content="API docs for the getForvoResults method from the ForvoAudioEnhancement class, for the Dart programming language.">
  <title>getForvoResults method - ForvoAudioEnhancement class - creator library - Dart API</title>


  
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" rel="stylesheet">
  
  <link rel="stylesheet" href="../../static-assets/github.css?v1">
  <link rel="stylesheet" href="../../static-assets/styles.css?v1">
  <link rel="icon" href="../../static-assets/favicon.png?v1">

  
</head>


<body data-base-href="../../" data-using-base-href="false" class="light-theme">

<div id="overlay-under-drawer"></div>

<header id="title">
  <span id="sidenav-left-toggle" class="material-symbols-outlined" role="button" tabindex="0">menu</span>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="../../index.html">yuuna</a></li>
    <li><a href="../../creator/creator-library.html">creator</a></li>
    <li><a href="../../creator/ForvoAudioEnhancement-class.html">ForvoAudioEnhancement</a></li>
    <li class="self-crumb">getForvoResults method</li>
  </ol>
  <div class="self-name">getForvoResults</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
  <div class="toggle" id="theme-button">
    <label for="theme">
      <input type="checkbox" id="theme" value="light-theme">
      <span id="dark-theme-button" class="material-symbols-outlined">
        brightness_4
      </span>
      <span id="light-theme-button" class="material-symbols-outlined">
        brightness_5
      </span>
    </label>
  </div>
</header>
<main>

  <div id="dartdoc-main-content" class="main-content">
      <div>
<h1><span class="kind-method">getForvoResults</span> method 
</h1></div>

    <section class="multi-line-signature">
      

<span class="returntype"><a href="https://api.flutter.dev/flutter/dart-async/Future-class.html">Future</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.flutter.dev/flutter/dart-core/List-class.html">List</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../../creator/ForvoResult-class.html">ForvoResult</a></span>&gt;</span></span>&gt;</span></span>
<span class="name ">getForvoResults</span>(<wbr><ol class="parameter-list"><li><span class="parameter" id="getForvoResults-param-appModel">{<span>required</span> <span class="type-annotation"><a href="../../models/AppModel-class.html">AppModel</a></span> <span class="parameter-name">appModel</span>, </span></li>
<li><span class="parameter" id="getForvoResults-param-searchTerm"><span>required</span> <span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-core/String-class.html">String</a></span> <span class="parameter-name">searchTerm</span>}</span></li>
</ol>)

      

    </section>
    
<section class="desc markdown">
  <p>Return a list of pronunciations from a search term.</p>
</section>


    
<section class="summary source-code" id="source">
  <h2><span>Implementation</span></h2>
  <pre class="language-dart"><code class="language-dart">Future&lt;List&lt;ForvoResult&gt;&gt; getForvoResults(
    {required AppModel appModel, required String searchTerm}) async {
  Codec&lt;String, String&gt; stringToBase64Url = utf8.fuse(base64Url);
  Language language = appModel.targetLanguage;
  String cacheKey = &#39;${language.languageCode}&#47;$searchTerm&#39;;

  List&lt;ForvoResult&gt; results = [];
  if (_forvoCache[cacheKey] != null) {
    results = _forvoCache[cacheKey]!;
  } else {
    http.Response response =
        await _client.get(Uri.parse(&#39;https:&#47;&#47;forvo.com&#47;word&#47;$searchTerm&#47;&#39;));
    var document = parser.parse(response.body);

    try {
      String className = &#39;&#39;;

      &#47;&#47; Language Customizable
      if (appModel.targetLanguage is JapaneseLanguage) {
        className = &#39;pronunciations-list-ja&#39;;
      } else if (appModel.targetLanguage is EnglishLanguage) {
        className = &#39;pronunciations-list-en_usa&#39;;
      }

      List&lt;dom.Element&gt; liElements = document
          .getElementsByClassName(className)
          .first
          .children
          .where((element) =&gt;
              element.localName == &#39;li&#39; &amp;&amp;
              element.children.first.id.startsWith(&#39;play_&#39;))
          .toList();

      results = liElements.map((element) {
        String onClick = element.children[0].attributes[&#39;onclick&#39;]!;
        String? contributor = element.children[1].attributes[&#39;data-p2&#39;];

        if (contributor == null) {
          element.children
              .where((child) =&gt;
                  child.className == &#39;more&#39; || child.className == &#39;from&#39;)
              .toList()
              .forEach((child) =&gt; child.remove());

          contributor = element.text
              .replaceAll(
                  RegExp(r&#39;[\s\S]*?(?=Pronunciation by)Pronunciation by&#39;), &#39;&#39;)
              .trim();
        }

        String onClickCut = onClick.substring(onClick.indexOf(&#39;,&#39;) + 2);
        String base64 = onClickCut.substring(0, onClickCut.indexOf(&quot;&#39;&quot;));

        String fileUrl = stringToBase64Url.decode(base64);

        String audioUrl = &#39;https:&#47;&#47;audio.forvo.com&#47;mp3&#47;$fileUrl&#39;;

        return ForvoResult(
          audioUrl: audioUrl,
          contributor: contributor,
        );
      }).toList();

      _forvoCache[cacheKey] = results;
    } catch (error) {
      debugPrint(&#39;$error&#39;);
    }
  }

  return results;
}</code></pre>
</section>


  </div> <!-- /.main-content -->

  <div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
    <header id="header-search-sidebar" class="hidden-l">
  <form class="search-sidebar" role="search">
    <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
  <li><a href="../../index.html">yuuna</a></li>
  <li><a href="../../creator/creator-library.html">creator</a></li>
  <li><a href="../../creator/ForvoAudioEnhancement-class.html">ForvoAudioEnhancement</a></li>
  <li class="self-crumb">getForvoResults method</li>
</ol>


    <h5>ForvoAudioEnhancement class</h5>
    <ol>

        <li class="section-title"><a href="../../creator/ForvoAudioEnhancement-class.html#constructors">Constructors</a></li>
          <li><a href="../../creator/ForvoAudioEnhancement/ForvoAudioEnhancement.html">ForvoAudioEnhancement</a></li>


        <li class="section-title inherited">
          <a href="../../creator/ForvoAudioEnhancement-class.html#instance-properties">Properties</a>
        </li>
          <li class="inherited"><a href="../../creator/Enhancement/description.html">description</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/descriptionLocalisation.html">descriptionLocalisation</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/field.html">field</a></li>
          <li class="inherited"><a href="https://api.flutter.dev/flutter/dart-core/Object/hashCode.html">hashCode</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/icon.html">icon</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/label.html">label</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/labelLocalisation.html">labelLocalisation</a></li>
          <li class="inherited"><a href="https://api.flutter.dev/flutter/dart-core/Object/runtimeType.html">runtimeType</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/uniqueKey.html">uniqueKey</a></li>

        <li class="section-title"><a href="../../creator/ForvoAudioEnhancement-class.html#instance-methods">Methods</a></li>
          <li><a href="../../creator/ForvoAudioEnhancement/enhanceCreatorParams.html">enhanceCreatorParams</a></li>
          <li><a href="../../creator/ForvoAudioEnhancement/fetchAudio.html">fetchAudio</a></li>
          <li><a href="../../creator/ForvoAudioEnhancement/getForvoResults.html">getForvoResults</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/getLocalisedDescription.html">getLocalisedDescription</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/getLocalisedLabel.html">getLocalisedLabel</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/initialise.html">initialise</a></li>
          <li class="inherited"><a href="https://api.flutter.dev/flutter/dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
          <li class="inherited"><a href="../../creator/Enhancement/prepareResources.html">prepareResources</a></li>
          <li class="inherited"><a href="https://api.flutter.dev/flutter/dart-core/Object/toString.html">toString</a></li>

        <li class="section-title inherited"><a href="../../creator/ForvoAudioEnhancement-class.html#operators">Operators</a></li>
          <li class="inherited"><a href="https://api.flutter.dev/flutter/dart-core/Object/operator_equals.html">operator ==</a></li>




        <li class="section-title"><a href="../../creator/ForvoAudioEnhancement-class.html#constants">Constants</a></li>
          <li><a href="../../creator/ForvoAudioEnhancement/key-constant.html">key</a></li>
</ol>

  </div><!--/.sidebar-offcanvas-->

  <div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    yuuna
      2.8.0+93
  </span>

  
</footer>



<script src="../../static-assets/highlight.pack.js?v1"></script>
<script src="../../static-assets/docs.dart.js"></script>



</body>

</html>

